Class: fcf::Exception
Package: fcfBasis
File:
bits/PartException/ExceptionDecl.hpp
Implementation file:
bits/PartException/Exception.hpp
(
link_to_the_implementation_in_the_file
)
Available from version: 1.0.1
Checks whether the exception object contains any error information (a non-empty message).
The operator bool method provides a convenient way to check if an fcf::Exception object is "active".
An exception is considered true if a non-empty message name is associated with it.
Result
bool
- Returns true if the exception has a valid, non-empty message; false otherwise.
Example: Checking exception state
Demonstrating how to use the boolean operator to distinguish between empty and populated exception objects.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
#include <iostream>
int main() {
// 1. Create an empty exception object
fcf::Exception emptyEx;
// Check if emptyEx is "true" (it should be false because it has no message)
if (!emptyEx) {
std::cout << "Exception is empty." << std::endl;
}
// 2. Create a populated exception object with a message
fcf::Exception populatedEx("MY_ERROR", "Something went wrong", __FILE__, __LINE__);
// Check if populatedEx is "true" (it should be true because it has a message)
if (populatedEx) {
std::cout << "Exception is populated: " << populatedEx.what() << std::endl;
}
return 0;
}
Output:
Exception is empty.
Exception is populated: Something went wrong
Position: /home/user/application/main.cpp:15
The operator bool method effectively allows using exception objects in boolean contexts to quickly verify if they contain error details.